﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ADO.NET.Samples.Common;

namespace ADO.NET.Samples.Forms.LINQ
{
    [FormDescription("Basic LINQ Query", "Demonstrate how to use LINQ query.")]
    public partial class BasicLINQQuery : Form
    {
        public BasicLINQQuery()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Add data to listbox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BasicLINQQuery_Load(object sender, EventArgs e)
        {
            List<ArticleCategory> catesList = DBCommon.GetAllCategories();
            var cates = from cate in catesList
                        where cate.CategoryID > 1 && cate.CategoryID < 4
                        orderby cate.CategoryID descending
                        select cate;
            foreach (var cate in cates)
            {
                this.listBox1.Items.Add(cate.CategoryName);
            }
        }
    }
}
